<!--
 * @Author: 胡海
 * @Date: 2020-11-22 16:01:40
 * @LastEditors: 胡海
 * @LastEditTime: 2020-11-22 16:03:49
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Object.defineProperty</title>
    <script src="../vue/src/vue.js"></script>
</head>
<body>
    <div id="app">
        <button id="btn">改变数据</button>
        <h2 id="title">这是标题</h2>
    </div>

    <script>
        var data = {
            title: '新闻'
        }


        // Object.defineProperty

        // 定义属性，也可在原有的属性上描述

        Object.defineProperty(data,'miaov',{
            value: 'ketang',
            enumerable: true
        })

        Object.defineProperty(data,'title',{
            configurable: true,
            value: '重新定义了',
            enumerable:true,
            writable: false   // 设置false，不允许改写
        })

        data.title = '我要改变了'

        /*console.log(data.title);

        console.log(data);*/

        for(var attr in data){
            console.log(attr);
        }

        // 删除对象的属性
        delete data.title

        console.log(data);



    </script>
</body>
</html>